<script setup lang='ts'>
import { getUserBlogList } from '@/api/user';
import { BlogType } from '@/models/blog';
import { Ref, ref } from 'vue';


// 获取帖子list
const blogLoad = ref(false)
const blogFinished = ref(false)
const blogList:Ref<BlogType[]> = ref([])
const blogCurrentPage = ref(0)
const getBlog = async () => {
  const res = await getUserBlogList(blogCurrentPage.value)
  if(res.data.code === 0){
    if(res.data.data.records.length>0){
       blogList.value.push(...res.data.data.records)
    }else {
      blogFinished.value = true
    }
    blogLoad.value = false
  }
}
const blogOnLoad = async () => {
  blogCurrentPage.value++
  await getBlog()
}

// 刷新
const isLoading = ref(false)
const onRefresh = () => {
  blogFinished.value = false
  blogCurrentPage.value = 1
  blogList.value = []
  blogLoad.value = false
  getBlog()
  isLoading.value = false;  
}
</script>
<template>
  <van-pull-refresh
    v-model="isLoading"
    success-text="刷新成功"
    @refresh="onRefresh"
  >
  <van-list
    v-model:loading="blogLoad"
    :finished="blogFinished"
    finished-text="没有更多了"
    @load="blogOnLoad"
  >
    <BlogCartList :blog-list="blogList"></BlogCartList>
  </van-list>
  </van-pull-refresh>


</template>
<style scoped >
</style>
